import time


class Bar:
    user_progress = []

    def set_progress(self, user_id, current_num, total_num):
        is_has = False
        for key in self.user_progress:
            if key.get("user_id") == user_id:
                key["current"] = current_num
                key["total"] = total_num
                is_has = True
        if not is_has:
            self.user_progress.append({"user_id": user_id, "current": current_num, "total": total_num})

    def get_progress(self, user_id):
        for key in self.user_progress:
            if key.get("user_id") == user_id:
                # print(key)
                current = key.get("current")
                total = key.get("total")
                return current / total

    def go(self, notitys, user_id):
        currt_num = 1
        point_num = 0
        for n in notitys:
            time.sleep(0.5)
            self.set_progress(user_id, currt_num, len(notitys))
            progress = int(self.get_progress(user_id) * 50)
            progress_str = (' ' * (50 - progress))
            loading_str = "SUCCESS " if progress == 50 else "loading "
            point = "." * (point_num % 4)
            print('\r' + f"{loading_str} {'-' * progress}{progress_str}  {progress * 2}%  loading {point}", end='',
                  flush=True)
            # print(self.get_progress(user_id))
            currt_num += 1
            point_num += 1


if __name__ == '__main__':
    a = Bar()
    a.go([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
          16, 17, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
          14, 15, 16, 17], 1)
